package chaw.android.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import android.graphics.Bitmap;
import android.os.Environment;

public class ImageSave {

    public static String saveBitmap(Bitmap bm, String path){
    	File output = new File(path);
    	if(!output.isDirectory()){
    		output.mkdirs();
    	}
    	
    	String temp = path + "/" + System.currentTimeMillis() + ".jpg";
    	FileOutputStream out = null;
		try {
			out = new FileOutputStream(temp);
	        bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return temp;
    }
    
    public static void saveBitmapOnPath(Bitmap bm, String path){
    	File output = new File(path);
    	if(!output.isDirectory()){
    		output.mkdirs();
    	}
    	
    	FileOutputStream out = null;
		try {
			out = new FileOutputStream(path);
	        bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    public static String getImageDir(){
    	String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/TrainTravelers";
    	File output = new File(path);
    	if(!output.isDirectory()){
    		output.mkdirs();
    	}
    	return path;
    }
}
